package com.example.a313ldy.yuejian_17.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.TextView;

import com.example.a313ldy.yuejian_17.R;

/**
 * Created by LDY on 2017/10/25.
 */

public class Activity_pay extends AppCompatActivity {
    private TextView act_name;
    private TextView act_price;
    private TextView act_num;
    private TextView tele;
    private Button ConfirmPurchase;
    private ImageButton back;


    private RadioButton radioButton2;
    final GlobalValue globalValue = new GlobalValue();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay);
        initView();
    }

    private void initView() {
        Intent intent = getIntent();
        act_name =(TextView)findViewById(R.id.act_name);
        act_name.setText(intent.getStringExtra("name"));

        act_price = (TextView) findViewById(R.id.act_price);
        act_price.setText(intent.getStringExtra("act_price"));

        act_num = (TextView)findViewById(R.id.act_num);
        act_num.setText(intent.getStringExtra("act_num"));

        tele = (TextView)findViewById(R.id.tele);
        tele.setText(intent.getStringExtra("telephone"));




        radioButton2 = (RadioButton)findViewById(R.id.radioButton2);

        ConfirmPurchase = (Button)findViewById(R.id.ConfirmPurchase);
        ConfirmPurchase.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =  new Intent(Activity_pay.this,Activity_paydetail.class);
                startActivity(intent);
                //onBackPressed();
            }
        });

        back = (ImageButton)findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Intent intent =  new Intent(Activity_pay.this,MainActivity.class);
                //startActivity(intent);
                onBackPressed();
            }
        });
        radioButton2.setOnClickListener(new Listener());


    }



    class Listener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            switch (v.getId()){

                case R.id.radioButton2:
                    boolean isCheck = globalValue.isCheck();
                    if(isCheck)
                    {
                        if(v==radioButton2)radioButton2.setChecked(false);
                    }
                    else
                    {
                        if(v==radioButton2)radioButton2.setChecked(true);
                    }
                    globalValue.setCheck(!isCheck);
                    break;
                default:
                    break;
            }
        }
    }

    public class GlobalValue {
        public boolean isCheck() {
            return isCheck;
        }

        public void setCheck(boolean check) {
            isCheck = check;
        }

        private boolean isCheck;
    }
}